<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="../taglibs.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>回复评论</title>
<link rel="stylesheet" type="text/css" href="${path}/static/common/bootstrap-3.3.7-dist/css/bootstrap.css"/>
<link rel="stylesheet" type="text/css" href="${path}/static/common/layui/css/layui.css"/>
</head>
<body>
	<h3 style="text-align:center;font-family:'楷体';">回复用户评论</h3>
	<hr>
	<form id="form" class="layui-form layui-form-pane" action="">
	   <div class="layui-form-item" style="display: none">
	    <label class="layui-form-label">id</label>
	    <div class="layui-input-block">
	      <input type="text" name="id" autocomplete="off"  value = "${suggest.id }" class="layui-input">
	    </div>
	  </div>
	   <div class="layui-form-item" style="display: none">
	    <label class="layui-form-label">用户名</label>
	    <div class="layui-input-block">
	      <input type="text" name="username" autocomplete="off"  value = "${suggest.username }" class="layui-input">
	    </div>
	  </div>
	  
	  <h4><span style = "font-family:'楷体';">评价：</span>${suggest.suggest }</h4>
	  <hr>
	  <h4 style = "margin-top:50px;"><span style = "font-family:'楷体';">发表用户：</span>${suggest.username }</h4>
	  <h4><span style = "font-family:'楷体';">发表时间：</span>${suggest.createTime }</h4>
	  <hr>
	  <div class="layui-form-item" style = " margin-top:20px;">
	    <label class="layui-form-label">回复</label>
	    <div class="layui-input-block">
	      <input type="text" name="reply" autocomplete="off" placeholder="${suggest.reply }" value="${suggest.reply }" class="layui-input">
	    </div>
	  </div>
	  
	  <hr>
	  
   </form>
   <button class="layui-btn" onclick="submitForm()" style="display:block;margin:0 auto">发布</button>
   
   
   <script src="${path}/static/common/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/layer/layer.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/mylayer.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/layui/layui.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/kindeditor/kindeditor.js" type="text/javascript" charset="utf-8"></script>
   <script src="${path}/static/common/kindeditor/lang/zh_CN.js" type="text/javascript" charset="utf-8"></script>
   
   <script>
    	//正则表达式
    	function checkphone(){
    		var phone = $("#phone").val();
    		console.log("phone = " +phone);
    		
    		var pattern = /^1[34578]\d{9}$/; 
 			//if (!pattern.test(name)) {
 			if (pattern.test(phone) == false) {
 				mylayer.errorMsg("格式非法，手机号码当以1开头并至少为11位");
 			}
    	}
    	
	     function checkpas(){//当第一个密码框失去焦点时，触发checkpas1事件
	       var pas1=document.getElementById("password").value;
	       console.log("pas1 = " + pas1);
	       
		    var pattern = /^[0-9a-zA-Z]{2,8}$/;
			//if (!pattern.test(name)) {
			if (pattern.test(pas1) == false) {
				mylayer.errorMsg("格式非法，请输入 2-8位的数字或者字母");
			}
		}
   </script>
   
   <script type="text/javascript">
   	   layui.use(["form", "upload"], function() {
   			var form = layui.form;
   			var upload = layui.upload;
   			
   		    //普通图片上传
	   		var uploadInst = upload.render({
	   		    elem: '#uploadBtnId'
	   		    ,url: '${path}/upload/uploadImg.action' //改成您自己的上传接口
	   		    ,before: function(obj){// 这个预览是在前台，和后台没有关系
	   		      //预读本地文件示例，不支持ie8
	   		      obj.preview(function(index, file, result){
	   		        $('#mainImageId').attr('src', result); //图片链接（base64）
	   		      });
	   		    }
	   		    ,done: function(result){
	   		       if(result.success) {
	   		    	   // result.data返回的是图片的名字
	   		    	   $("#mainImageInputId").val(result.data);
	   		       }
	   		    }
	   		    ,error: function(){
	   		      //演示失败状态，并实现重传
	   		      var demoText = $('#demoText');
	   		      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
	   		      demoText.find('.demo-reload').on('click', function(){
	   		        uploadInst.upload();
	   		      });
	   		    }
	   		});
   			
   			form.on("select(topCategoryFilter)", function(data) {
   				// data代表当前选中的option标签对象(js dom)
   				console.log(data.value);// 被选中的option的value值
   				// 根据一级分类去加载二级二类
   				$.post(
   					"${path}/category/selectSecondCategoryByTopCategoryId.action",
   					{"topCategoryId" : data.value},
   					function(result) {
   						console.log(result);
   						$("#secondCategoryId").empty();
   						// result.data  List<Category> secondCategoryList;
   						$("#secondCategoryId").append("<option value=''>请选择二级分类</option>");
   						$(result.data).each(function() {
   							// this代表当前正在遍历的Category对象
   							var html = "<option value='"+this.id+"'>"+this.name+"</option>";
   							$("#secondCategoryId").append(html);
   						});
   						// 刷新select标签，重新渲染
   						form.render("select");
   					},
   					"json"
   				);
   			});
   			
   			
   			
   	   });
   
	   function submitForm() {
			$.post(
				"${path}/suggest/replyNow.action",
				$("#form").serialize(),
				function(result) {
					console.log(result);
					if(result.success) {
						mylayer.successMsg(result.msg);
						//当你在iframe页面关闭自身时获得当前弹出框的index索引
						var index = parent.layer.getFrameIndex(window.name);
						// js一个方法，定时器，1000毫秒之后自动执行function里面的代码
						setTimeout(function() {
							 // 关闭弹出层
							 parent.layer.close(index); 
							 // 刷新父页面
							 window.parent.location.reload();
						}, 1000);
					} else {
						mylayer.errorMsg(result.msg);
					}
				},
				"json"
			);
		}
	   
	   KindEditor.ready(function(K) {
		    var kingEditorParams = {
		         afterBlur: function () { this.sync(); }
		    }
		    KindEditor.create('#editor_id', kingEditorParams);
		});
	</script>
</body>
</html>